<template>
	<!--  自提地址选择-->
	<view :class="['sww-address-box',vuex_config.self_mention == 1?'bor_top':'']" >
		<u-icon @click="goSelect()" name="e769" size="44" color="#666666" custom-prefix="iconfont"></u-icon>
		<block v-if="pickForm.pk_id ? true : false">
			<view class="s-a-content" @click="goSelect()">
				<view class="s-a-top">
					<text class="">{{ pickForm.name }}</text>
					<text class="u-m-l-24">{{ pickForm.phone }}</text>
				</view>
				<view class="s-a-detail u-m-t-6">{{ pickForm.address }}</view>
			</view>
			<u-checkbox v-if="vuex_config.self_mention != 1" v-model="checkPick" :active-color="vuex_config.themeColor1"
				shape="circle" @change="goChange">
			</u-checkbox>
		</block>
		<block v-else>
			<view @click="goSelect()" class="s-a-content">请选择自提地址</view>
		</block>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		components: {},
		data() {
			return {
				bol: 1,
				pickForm: {}, // 当前显示的自提地址
				checkPick: false, // 是否选择了当前显示d的自提地点
				init: false
			};
		},
		props:{
			prodId:{
				type:['string','number'],
				default:''
			}
		},
		computed: {
			...mapState(['vuex_pick'])
		},
		methods: {
			$show() {
				let pickForm = {}
				if (this.vuex_config.self_mention != 1) {
					if (!this.init) { // 第一次进来
						uni.removeStorage({
							key: 'pickForm'
						});
						this.init = true
					}

					uni.getStorage({
						key: 'pickForm',
						success: res => {
							if (res.data && res.data.pk_id) {// 临时缓存的
								pickForm = {
									...res.data
								}
							} else if (this.vuex_pick) {// 全局设置/自提商城
								pickForm = {
									...this.vuex_pick
								}
							}

							if (pickForm.pk_id) {
								this.checkPick = true;
								this.$emit('changPick', true);
							}
							this.pickForm = {
								...pickForm
							}
						},
						fail: (err) => {
							if (this.vuex_pick) {
								pickForm = {
									...this.vuex_pick
								}
							}
							if (pickForm.pk_id) {
								this.checkPick = true;
								this.$emit('changPick', true);
							}
							this.pickForm = {
								...pickForm
							}
						}
					});
				} else {
					if (this.vuex_pick) {
						pickForm = {
							...this.vuex_pick
						}
					}
					if (pickForm.pk_id) {
						this.checkPick = true;
						this.$emit('changPick', true);
					}
					this.pickForm = {
						...pickForm
					}
				}
			},
			// 切换选择自提地址
			goChange(e) {
				this.$emit('changPick', e.value);
			},
			goSelect() {
				if (this.vuex_config.self_mention == 1) {
					this.$linkTo(`/package/product/local/pickUpAddress/index`);
				} else {
					this.$linkTo(`/package/product/local/pickUpAddress/index?prodId=${this.prodId}`);
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.bor_top {
		border-top: 1px solid #F5F5F5;
	}

	.sww-address-box {
		width: 100%;
		min-height: 144rpx;
		background-color: #ffffff;
		padding: 30rpx;
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #f5f5f5;

		.s-a-content {
			flex: 1;
			overflow: hidden;
			margin: 0 24rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			font-size: 26rpx;
			color: #666666;
		}
	}
</style>
